﻿<%@ Control Language="C#" Inherits="Yuanlin.Business.ZiCaiInfoAddControl, Yuanlin.Business"
    AutoEventWireup="true" %>
<%@ Register TagPrefix="ctrl" TagName="Editor" Src="~/themes/default/skins/Skin-HtmlEditor.ascx" %>

<script type="text/javascript">
<!--
    function CheckValue()
    {
        var select = document.getElementById('<%= secondZiCaiCategoryDropDownList.ClientID %>');
        var hasSelected = false;
        for(var i = 0; i < select.length; i++)
        {   
            if(select[i].selected && i > 0)
            {
                hasSelected = true;
                break;
            }   
        }   
        if(hasSelected == false)
        {   
            alert('请选择类别！');
            select.focus();
            return false;
        }
                
        var title = document.getElementById('<%= titleValuedTextBox.ClientID %>');
        if (title.value.Trim() == "")
        {
            alert('请输入名称！');
            title.focus();
            return false;
        }
        
        var price =  document.getElementById('<%= priceValuedTextBox.ClientID %>');
        if(price.value.Trim().length > 0)
        {
            if(!isNumber(price.value.Trim()))
            {
                alert('价格应为数字！')
                price.focus();
                return false;
            }
            var overb = false;
            if(price.value.Trim().indexOf('.')>-1)//存在小数点
            {
                if(price.value.Trim().substr(0,price.value.Trim().indexOf('.')).length>7)
                {
                    overb=true;
                }
            }
            else if(price.value.Trim().length>7)
            {
                overb=true;
            }
            if(overb)
            {
                alert('价格不能大于7位！')
                price.focus();
                return false;
            }
        }
        
         var selected = false;
        var leng=0; 
        var rows=0;
        var childid;
        
        var category = document.getElementById('<%= categoryRadioButtonList.ClientID %>');
        if (category != null)
        {
            selected = false;
            rows = category.rows.length;
            for(var j=0;j<rows;j++)
            {
                leng=category.rows[j].cells.length; 
                for(var i=0;i<leng;i++)
                {
                  childid='<%= categoryRadioButtonList.ClientID %>'+'_'+(parseInt(j*leng)+parseInt(i));
                  if(document.getElementById(childid)!=null &&  document.getElementById(childid).checked)
                  {
                      selected = true;
                      break;
                  }      
                }
            }
            if(!selected)
            {
                alert('请选择植物分类！');
                return false;
            }
        }
        
        //分类的规格
        var specificationHiddenField = document.getElementById('<%= specificationHiddenField.ClientID %>');
        var dyCreate = document.getElementById('dyCreate');
        if(dyCreate.childNodes.length>0)
        {
            var values="";
            for(var i=0;i<dyCreate.childNodes.length;i++)
            {
                if(dyCreate.childNodes[i].childNodes[2].value.length>0 && !isNumber(dyCreate.childNodes[i].childNodes[2].value))
                {
                    alert('请在规格中输入数字！');
                    dyCreate.childNodes[i].childNodes[2].focus();
                    return false;
                }
                values+=";"+dyCreate.childNodes[i].childNodes[0].value+":"+dyCreate.childNodes[i].childNodes[2].value+":"+dyCreate.childNodes[i].childNodes[4].value;
            }
            if(values.length>0)
            {
                specificationHiddenField.value = values.substr(1);
            }
        }
    }
    function GetChildCategories()
    {
        var parentCategoryID = document.getElementById('<%= topZiCaiCategoryDropDownList.ClientID %>').value;
        if(parentCategoryID != null)
        {             
	        AjaxMethod.GetChildCategories('<%=ClientID %>', parentCategoryID,  GetChildCategoriesCallBack);
        }
    }
    
    function GetChildCategoriesCallBack(res)
    {
        var secondZiCaiCategoryValuedDropDownList = document.getElementById('<%= secondZiCaiCategoryDropDownList.ClientID %>');
        
        ClearOptionsWithDefault(secondZiCaiCategoryValuedDropDownList, "<请选择>");
        
        if(res.value == null || res.value == "")
        {
            return;
        }   
        var categories = res.value.split(";");
        for(var i = 0; i < categories.length; i++) { 
            var category = categories[i].split(":");
            var newOption=new Option(category[1],category[0]);
            secondZiCaiCategoryValuedDropDownList.options.add(newOption); 
        }  

        if(secondZiCaiCategoryValuedDropDownList.length > 0)
        {
            secondZiCaiCategoryValuedDropDownList.selectedIndex = 0; 
        }
    }

    function ClearOptions(list) 
    { 
        while (list.options.length > 0) 
        { 
            list.options[0] = null; 
        } 
    }
    
    function ClearOptionsWithDefault(list, defaultValue) 
    { 
        while (list.options.length > 0) 
        { 
            list.options[0] = null; 
        }
        var newOption=new Option(defaultValue, -1);
        list.options.add(newOption);
    }
    
    function categoryClick()
    {
       var obj = document.getElementById('<%= categoryRadioButtonList.ClientID %>');
       var radInput = obj.getElementsByTagName("INPUT");   
       var radLable = obj.getElementsByTagName("Label");   
         
       for(var i=0;i<radInput.length;i++)   
       {   
         if(radInput[i].checked)   
          {   
              AjaxMethod.ParentCategorySelectedChanged('<%=ClientID %>', radInput[i].value,CategorySelectedChangedCallBack); 
          }   
       }   
    }
    function CategorySelectedChangedCallBack(res)
    {
        var dyCreate = document.getElementById("dyCreate");
        dyCreate.innerHTML="";
        
        if(res.value == null || res.value == "")
        {
            return;
        } 
        var specificationvalues=res.value;//规格
        if(specificationvalues.length>0)//规格
        {
            CreateGuiGeControl(dyCreate,specificationvalues.split(";"));
        }
    }
    function CreateGuiGeControl(dyCreate,values)
    {
        for(var i=0;i<values.length;i++)
        {
            if (values[i] == "")
            {
                continue;
            }
            var data = values[i].split(":");
            var div = document.createElement("div");
            div.style.marginTop="5px";
            div.style.paddingLeft="30px";
            div.style.width="29%";
            div.style.overflow="hidden";
            div.style.styleFloat="left"; 
            
            var input = document.createElement("input");
            input.setAttribute("type", "hidden"); 
            input.setAttribute("name", "ctl01$bcr$ctl01$list$ctl0"+i+"$fieldName"); 
            input.setAttribute("id", "ctl01_bcr_ctl01_list_ctl0"+i+"_fieldName"); 
            input.setAttribute("value",data[0]);
             
            var label = document.createElement("label");
            label.style.display="block";
            label.style.styleFloat="left";
            label.style.width="6em";
            label.style.paddingTop="0.5em";
            label.style.paddingRight="1em";
            label.style.textAlign="right";
            label.style.fontSize="12px"; 
            label.setAttribute("for", data[0]);
            var textNode = document.createTextNode(data[0]); 
            label.appendChild(textNode);
            
            var inputFieldValue = document.createElement("input");
            inputFieldValue.setAttribute("type", "text"); 
            inputFieldValue.setAttribute("name", "ctl01$bcr$ctl01$list$ctl0"+i+"$fieldValue"); 
            inputFieldValue.setAttribute("id", "ctl01_bcr_ctl01_list_ctl0"+i+"_fieldValue"); 
            inputFieldValue.style.border="1px";
            inputFieldValue.style.borderStyle="solid";
            inputFieldValue.style.borderColor="#CCC";
            inputFieldValue.style.paddingTop="4px";
            inputFieldValue.style.width="30%";
            
            var labelproductunit = document.createElement("label");
            labelproductunit.style.display="inline-block";
            labelproductunit.style.width="4em";
            labelproductunit.style.paddingTop="0.5em";
            labelproductunit.style.paddingRight="1em";
            labelproductunit.style.textAlign="left";
            labelproductunit.style.fontSize="12px";
            var textNode = document.createTextNode(data[1]); 
            labelproductunit.appendChild(textNode);
            
            var inputFieldUnit = document.createElement("input");
            inputFieldUnit.setAttribute("type", "hidden"); 
            inputFieldUnit.setAttribute("name", "ctl01$bcr$ctl01$list$ctl0"+i+"$fieldUnit"); 
            inputFieldUnit.setAttribute("id", "ctl01_bcr_ctl01_list_ctl0"+i+"_fieldUnit"); 
            inputFieldUnit.setAttribute("value",data[1]);
            
            div.appendChild(input);
            div.appendChild(label);
            div.appendChild(inputFieldValue);
            div.appendChild(labelproductunit);
            div.appendChild(inputFieldUnit);
            
            dyCreate.appendChild(div);
        }
    }
//-->
</script>

<asp:HiddenField ID="specificationHiddenField" runat="server" />
<div class="AdminArea" style="height: 1000px; overflow-y: no;">
    <fieldset>
        <legend>
            <asp:Literal ID="zicaiInfoLiteral" runat="server"></asp:Literal></legend>
        <div class="FormRow">
            <div class="LargerFieldNameRequireCharacter">
                <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml"
                    ResourceName="RequireCharacter" />
                <nwap:ResourceLabel runat="Server" ControlToLabel="topZiCaiCategoryValuedDropDownList"
                    ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_ZiCaiInfo_ZiCaiClass" />
            </div>
            <nwap:ValuedDropDownList runat="server" CssClass="InputField" Width="120px" ID="secondZiCaiCategoryDropDownList" />
            <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml"
                ResourceName="RequireCharacter" />
            <nwap:ResourceLabel runat="Server" ControlToLabel="titleValuedTextBox" ResourceFile="ControlPanelResources.xml"
                ResourceName="System_Applications_Yuanlin_ZiCaiInfo_Title" />
            <nwap:ValuedTextBox runat="server" CssClass="InputField MicroWidth" ID="titleValuedTextBox" />
        </div>
        <div class="FormRow">
            <nwap:ResourceLabel CssClass="FieldName" runat="Server" ControlToLabel="attachmentData"
                ResourceFile="ControlPanelResources.xml" ResourceName="Attachment_UploadAttachment" />
            <input type="File" onchange="CheckImage(this)" id="attachmentData" class="InputField MiddleAttachmentDataWidth"
                runat="server" name="attachmentData" />
        </div>
        <div class="FormRow">
            <nwap:ResourceLabel CssClass="FieldName" runat="Server" ControlToLabel="registerTrademarkValuedTextBox"
                ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_ZiCaiInfo_RegisterTrademark" />
            <nwap:ValuedTextBox runat="server" CssClass="InputField MicroWidth" ID="registerTrademarkValuedTextBox" />
            <nwap:ResourceLabel runat="Server" ControlToLabel="priceValuedTextBox" ResourceFile="ControlPanelResources.xml"
                ResourceName="System_Applications_Yuanlin_ZiCaiInfo_Price" />
            <nwap:ValuedTextBox runat="server" CssClass="InputField MicroWidth" ID="priceValuedTextBox" />(元)
        </div>
        <div class="FormRow">
            <table width="100%">
                <tr valign="top">
                    <td>
                        <div class="LargerFieldNameRequireCharacter">
                            <nwap:ResourceLabel runat="Server" CssClass="RedColor" ResourceFile="ControlPanelResources.xml"
                                ResourceName="RequireCharacter" />
                            <nwap:ResourceLabel runat="Server" ControlToLabel="categoryRadioButtonList" ResourceFile="ControlPanelResources.xml"
                                ResourceName="System_Applications_Yuanlin_ZiCaiInfo_ZiCaiGuiGeCategory" />
                        </div>
                        <asp:RadioButtonList CssClass="CategoryCheckboxList" runat="server" RepeatDirection="Horizontal"
                            RepeatColumns="5" ID="categoryRadioButtonList" onclick="categoryClick()" />
                    </td>
                </tr>
            </table>
        </div>
        <div class="FormRow">
            <table width="100%">
                <tr valign="top">
                    <td>
                        <div id="dyCreate">
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div class="FormRow">
            <nwap:ResourceLabel CssClass="FieldName" runat="Server" ControlToLabel="descriptionValuedEditor"
                ResourceFile="ControlPanelResources.xml" ResourceName="System_Applications_Yuanlin_ZiCaiInfo_Body" />
            <br />
            <br />
            <ctrl:Editor runat="server" Width="100%" Height="250px" ID="descriptionValuedEditor" />
        </div>
        <div class="FormRow SubmitButtonRow">
            <nwap:ResourceButton ID="SaveButton" ResourceName="Save" CssClass="Button" runat="server"
                OnClientClick="return CheckValue()"></nwap:ResourceButton>&nbsp;&nbsp;&nbsp;&nbsp;
            <nwap:ResourceButton ID="BackButton" ResourceName="Back" CssClass="Button" runat="server">
            </nwap:ResourceButton>
        </div>
        <div style="visibility: hidden">
            <nwap:ValuedDropDownList runat="server" CssClass="InputField" Width="120px" onchange="GetChildCategories()"
                ID="topZiCaiCategoryDropDownList" />&nbsp;&nbsp;
        </div>
    </fieldset>
</div>
